﻿Imports NearAop
<AddProxyProperty(GetType(Proxy1))>
Public Class T04_属性外部代理
    Property MyProperty As Integer
    Sub Test()
        MyProperty += 1
        MyProperty += 1
    End Sub
End Class

Public Class Proxy1
    Implements IAopHandlerProperty

    Public Sub PropertySetHandler(Of T)(aopParamInfo As Lazy(Of AopParamInfo), sender As Object, value As T, getValue As Func(Of T), setValue As Action(Of T)) Implements IAopHandlerPropertySet.PropertySetHandler
        Dim propName = aopParamInfo.GetMemberName()
        Dim msg = $"{sender}.{propName}被修改, 修改前:{getValue()}, 新值:{value}"
        Console.WriteLine(msg)
        setValue(value) '执行修改
    End Sub

    Public Function PropertyGetHandler(Of T)(aopParamInfo As Lazy(Of AopParamInfo), sender As Object, getValue As Func(Of T)) As T Implements IAopHandlerPropertyGet.PropertyGetHandler
        Dim propName = aopParamInfo.GetMemberName()
        Dim result = getValue()
        Dim msg = $"{sender}.{propName}被读取,值:{result}"
        Console.WriteLine(msg)
        Return result
    End Function
End Class